package com.zcb.qingshoudan.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;


import com.zcb.qingshoudan.R;
import com.zcb.qingshoudan.adapter.GatherHistoryAdapter;
import com.zcb.qingshoudan.entity.GatheringHistoryVoDetails;
import com.zcb.qingshoudan.xrecyclerview.ProgressStyle;
import com.zcb.qingshoudan.xrecyclerview.XRecyclerView;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.zip.Inflater;

public class GatheringHistoryActivity extends Activity implements View.OnClickListener {
    private LinearLayout titleLinearLayout;
    private TextView titleTV;
    private XRecyclerView mRecyclerView;
    private TextView h;
    private TextView i;
    private GatherHistoryAdapter gatherHistoryAdapter;
    private List<GatheringHistoryVoDetails> gatheringHistoryVoDetailsList;
//    private c l;
    private Button m;
    private LinearLayout n;
    private int o = 1;
    private boolean p = true;
    private Date q;
    private SimpleDateFormat r;
    private String s;
    private int t;
    private int u;
    private int v;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_gathering_history);
        gatheringHistoryVoDetailsList=new ArrayList<GatheringHistoryVoDetails>();
        initView();
        initData(5);


    }

    private void initView(){
        mRecyclerView= (XRecyclerView) findViewById(R.id.gathering_history_recyclerview);
        //title main
        titleLinearLayout= (LinearLayout) findViewById(R.id.title_lin_back);
        titleTV= (TextView) findViewById(R.id.title_text);
        titleLinearLayout.setVisibility(View.VISIBLE);
        titleLinearLayout.setOnClickListener(this);
        titleTV.setText("收款记录");

        //创建默认的线性LayoutManager
        LinearLayoutManager linearLayoutManager=new LinearLayoutManager(this);
        mRecyclerView.setLayoutManager(linearLayoutManager);
        //
        gatherHistoryAdapter=new GatherHistoryAdapter(gatheringHistoryVoDetailsList);
        mRecyclerView.setAdapter(gatherHistoryAdapter);

        mRecyclerView.setRefreshProgressStyle(ProgressStyle.BallSpinFadeLoader);
        mRecyclerView.setLoadingMoreProgressStyle(ProgressStyle.BallRotate);
        mRecyclerView.setArrowImageView(R.drawable.iconfont_downgrey);
        View header= LayoutInflater.from(this).inflate(R.layout.activity_gathering_history_layout,(ViewGroup)findViewById(android.R.id.content),false);
        mRecyclerView.addHeaderView(header);
        mRecyclerView.setLoadingListener(new XRecyclerView.LoadingListener() {
            @Override
            public void onRefresh() {
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        initData(2);
                        gatherHistoryAdapter.notifyDataSetChanged();
                        mRecyclerView.refreshComplete();
                    }
                },2000);

            }

            @Override
            public void onLoadMore() {
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        initData(3);
                        gatherHistoryAdapter.notifyDataSetChanged();
                        mRecyclerView.refresh();
                    }
                },5000);

            }
        });
    }
    private void initData(int length){
        for (int i=0;i<length;i++){
        GatheringHistoryVoDetails detail=new GatheringHistoryVoDetails();
        detail.setAdd_time("2016-11-30 12:12:30");
        detail.setGoods_name("张三"+i);
        detail.setGoods_price(String.valueOf(145+i));
        gatheringHistoryVoDetailsList.add(detail);
        }
    }





    @Override
    public void onClick(View view) {
        switch(view.getId()){
            case R.id.title_lin_back:
                finish();
                break;

        }
    }
}
